package com.aaa.service.jl.impl;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.dao.sys.UserDao;
import com.aaa.service.jl.LoginService;
import com.aaa.service.sys.UserService;
import com.aaa.utils.MyTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private UserService userService;
    @Autowired
    private UserDao userDao;

    public boolean check(Map<String,Object> map) {
        String passwordTemp = map.get("searchPassword").toString();
        List<Map<String, Object>> mapList = userService.findAllUserInfoByName(map);
        if (null != mapList && mapList.size() > 0) {
            Map<String, Object> user =mapList.get(0);
            String salt = user.get("salt").toString();
            String password = user.get("password").toString();
            String s = MyTools.makePasswordSalt(passwordTemp, salt);
            if (password.equals(s)) {
                return true;
            }
        }
        return false;
    }

    public Map<String, Object> findUserInfoByName(Map map) {
        List<Map<String, Object>> mapList = this.userDao.findAllUserInfoByName(map);
        if (ObjectUtil.isNotEmpty(mapList)) {
            return  mapList.get(0);
        }
        return null;
    }
}